Skip to main content

Coding with ARDUINO


After understanding the connection making on bread board we connected our first output device- LED on Arduino board’s digital output pin 13, On the micro controller  pin 13 acted as positive terminal and GND- Ground act as zero or negative terminal.
 (blinking aurdino led) it was blinking because the the reset code used was blink.

The Coding for this command was -

// the setup function runs once when you press reset or power the board

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

*Here the words – HIGH & LOW in digitalwrite means ON & OFF for  any Digital output and delay is time in milli seconds and can be altered accordingly.
The same command can be repeated by applying numerous LEDs on different pins and assigning them different codes. :)





LED with Buzzer : It did not need any other code as the same codes used for two output for 2 LEDs can be used as the number of outputs did not change.

Changing the LED with variable resistor , here TRIM, it is a small construction of potentiometer.



IR Sensor - We used IR sensor to detect IR emitting objects, maybe humans, and other objects.It can also detect any obstacle towards it is pointed. And it can be understood as digital output.
The code used :
the setup routine runs once when you press reset:
void setup() 
{
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(2, INPUT);
  pinMode(13,OUTPUT);
}

// the loop routine runs over and over again forever:
void loop()
 {
  // read the input pin:
  int ugPdl = digitalRead(3);
  if (ugPdl ==0)
  {
    Serial.println("Obstacle detected , Be careful");
    digitalWrite(13,HIGH);
    delay(1000); 
    digitalWrite(13, LOW); 
                
  }
  else
 {
 Serial.println("obstacle not detected , continue");
 digitalWrite(13,LOW);
 }
  
  // print out the state of the button:
  Serial.println(ugPdl);
  delay(1000);        // delay in between reads for stability

}
LDR Resistor -  As we knew that it can be used to detect changes in light and intensity of light. So to know the change  by the output device or can get the value on device used as output screen.(Here Laptop)
Code : 

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(19200);
// make the LDR sensor's pin an input:
pinMode(A0, INPUT);
pinMode(2, OUTPUT);     //here output refers to that of attached  LED's for visual data
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int a = analogRead(A0);
if (a>=x)
{
Serial.println("abcdef");
digitalWrite(2, HIGH);
}
else
{
Serial.println ("ghijkl");
digitalWrite(2, LOW);
delay (1000);
}


Servo Meter – Servo meter was used next on arduino UNO .The aim for using it with Arduino was using it at the specific angles as well as controlling the time period for repetition.
the code for it:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() 
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) 
// goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) 
// goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

{ERROR OCCURED WHILE UPLOADING VIDEO CONTENT}


DC Motor is any class of rotary electrical machines that converts direct current electrical energy into mechanical energy .


for this we will need a transmitter and wires , solder , solder stick and a screwdriver .
first solder two wires at both the terminals of the DC motor
then unscrew the screws at left or right forward and backward 
thereafter connect the two wires on the DC motor and tighten screws.
connect VCC , GND and pins 
The Code is:

Aim: To run the motor with the help of arduino board and transmitter 


code:


const int leftForward = 5;
const int leftBackward = 6;
const int rightForward = 4;
const int rightBackward = 2;

void setup() 
{
  pinMode(leftForward , OUTPUT);
  pinMode(leftBackward , OUTPUT);
  pinMode(rightForward , OUTPUT);
  pinMode(rightBackward , OUTPUT);

}

void loop()
{
  analogWrite(leftForward , 150);
  analogWrite(leftBackward , 0);
  delay(2000);
  analogWrite(leftForward , 0);
  analogWrite(leftBackward , 150);
  delay(2000);
  
  analogWrite(rightForward , 150);
  analogWrite(rightBackward , 0);
 delay(2000);
}









Comments

Popular posts from this blog

Learning basics : {NOSTALGIA HITS}

In our  beginning sessions , we were introduced the basics of current , resistance and circuitry and all so that we could relate the information in the real world and it does not seem like a theoretical sessions to just mug up the facts. In my higher secondary education, 3 years back I had Physics as one of my core subjects and I loved it. All the basics were just turning the pages of  my school lectures for me. So it was a bit nostalgic when same information was again being delivered to me. It helped me there. I made some notes on the learning session and merged my own thoughts as I knew the concepts already so that anyone reading them would understand them better . Current  – Flow of electrons is called as current. It can have 2 directions depending on the direction of flow of electrons. Unit of measurement of current is Ampere(A) Types of current Direct Current (DC) – Current which has only one direction and does not change its direction is ca...

Introducing New SUBJECT

As a product designer in making, I need to make prototypes and in today’s era there are minimal products which do not have a single circuit and uses only mechanics,  products have come a long way and have become more and more automatic. Like a a door is not just an entrance which is pushed to open, there are doors which open as soon as a human steps towards it. Simplest and biggest example of a product with sensors is right there with us right now our Smart phone. It has got accelerometer, gyroscope, proximity, motion sensors and has got many functions more than to just call and connect with people. To keep up with the world and make products in 2018 and further,   We  needed to understand their working and   start using them in prototyping stage and to do that we should have basic level of  understanding of available sensors , which are cheap, which one to use and to learn basic level programming . So all of the above is true and for that reason this...

Circuits without coding

To start with circuits, we understood  the basic sign and symbols and were ready to start with the circuits. First was as simple as just connecting the power source with one of the LED. For which we used our coin battery of 3 volts with LED Next was making the same circuit on bread board using burg wires (male to male), because the previous was very unstable. Next  was using a switch in the same circuit and control the flow of current when pushed the button. Next was using 450ohm and 10kilo ohm resistor to see the difference in LED intensity due to resistors and decreasing current flow. Now we changed the output device in first circuit, which was LED with a buzzer. Next was learning series and parallel connection on bread board. SWITCHES  :- Force Sensor – Force sensor is a variable resistance and can also work as switch.The force changes the value of resistance and in case of switch can close a ...