Wednesday, 26 February 2014

ARDUINO THE MAGIC OF OPEN SOURCE HARDWARE



READING ANALOG SENSORS FROM AN ARDUINO


Hello hardware hackers and enthusiasts today we want to continue with our arduino programming and opensource hardware programming trust me within no time you will be ready to build your robot,home automtion and other cool stuff

Today I want o take you gently on how to read from an analog sensor and display it in your pc
cool right this is a series that will teach you how to interface an arduino to the hardware nd lso begin to teach how to code it

REQUIREMENTS
Arduino R3  or any will work
jumper wires
LED to display the brightness according to the potentiometer value
potentiometer
an analog sensor like photoresistor, thermal sensor or thermister
jumper wires and some resistors
for information on the  photoresistor check out my other blog


 PROCEDURE
The potentiometer has three pins one in the centre and two other to the exteem left and right
connect the middle pin to the analog pin ieA0 of the Arduino this is because its an analog sensor or device 
Thn connect the other pins of the potentiometer to +5v  and GND of the arduino thats it very simple and easy to do for  a beginning
launch your arduino and then copy this code below guys notice the code is afree one and it comes as examples with the Arduino IDE
CODE
The code for this example is here: as i said its in your ide but i just modified it kidogo
int potPin = 0; //Analog input pin "0" that the potentiometer is attached to
int potValue = 0; //value read from the pot
int led = 9; //PWM pin that the LED is attached to (note: PWM 0 is on digital pin 9)

void setup(){
  //initialize serial communications at 9600 bps:
  Serial.begin(9600);
  //declare the LED pin as an output:
  pinMode(led,OUTPUT);
}

void loop(){
  potValue = analogRead(potPin); //read the pot value
  analogWrite(led,potValue/4); //PWM the LED with the pot value
  Serial.println(potValue); //print the pot value back to the debugger pane
  delay(10); //wait 10 milliseconds before the next loop
}
Lets now use it to control the speed of a motor

ENJOY YOUR FEED BACK IS HIGHLY WELCOMED nice

1 comment:

  1. Guys this is the second part of using sensors with arduino

    ReplyDelete