Você está na página 1de 8

Industrial Electronics & Robotics

LAB WORK

Submitted By

Muhammad Hamza
0557-BH-ELEC-14
B.Sc.(Hons.) Electronics (2014-2018)
Government College University, Lahore
Reading Analog Voltage

Arduino analog inputs can be used to measure DC voltage between 0 and 5V. The
range over which the Arduino can measure voltage can be increased by using two
resistors to create a voltage divider. The voltage divider decreases the voltage being
measured to within the range of the Arduino analog inputs. Code in the Arduino sketch
is then used to calculate the actual voltage being measured.This allows voltages greater
than 5V to be measured.

Fig: The circuit layout

Steps to perform

1. Place the potentiometer into your breadboard.


2. Run a jumper wire from the 5-Volt pin of the Arduino to either one of the outside
pins of the potentiometer.
3. Run another jumper wire from one of the ground pins on the Arduino (labeled
GND) to the other outside pin of the potentiometer.
4. Run the final jumper wire from pin A0 on the Arduino to the middle pin of the
potentiometer.
5. Plug the Arduino into your computer.
6. Open up the Arduino IDE.
7. Open the sketch for this section.
8. Click the Verify button on the top left side of the screen. It will turn orange and
then back to blue once it has finished.
9. Click the Upload button (next to the Verify button). It will turn orange and then
back to blue once it has finished.
10. On the menu bar, go to Tools > Serial Monitor – this will open the Serial Monitor
window – you should see numbers rolling down this screen.
11. Now adjust the knob of your potentiometer and watch the serial monitor window,
the numbers should adjust between 0 and 5.

Program

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:


void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
Tachometer with Arduino

A tachometer is a device used to measure the or RPM Revolutions Per Minute of any
rotating body. Tachometers can be contact based or non-contact ones. The non-contact
or contact-less optical tachometers usually use laser or Infrared beam to monitor the
rotation of any body. This is done by calculating time taken for one rotation.

Apparatus
● Arduino
● Resistors - 33k , 270 ohm , 10k potentiometer
● LED - blue
● LDR
● Motors and DC fan

Tachometer Readings

Steps

● First the +5v power and data control connections are made.
● The LED is connected, along with contrast control and power LED.
● The IR break beam circuit is now assembled. Try to keep a good distance
between the IR LED and phototransistor.
● The fan of the motor is rotated with a light incident on the LDR.
● The rpm is calculated through the formula and shown on the serial monitor.

Program

int ledPin = 13; // choose the pin for the LED


int switchPin =2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(switchPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
}

void loop(){
val = digitalRead(switchPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, HIGH); // turn LED on
currentState = 1;
}
else {
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
Serial.println(counter);
}
}
previousState = currentState;
delay(250); }
Ultrasonic Sensor With Arduino

Ultrasonic Sensor HC-SR04

It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object
or obstacle on its path It will bounce back to the module. Considering the travel time and
the speed of the sound you can calculate the distance.

The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground
and the VCC pins of the module needs to be connected to the Ground and the 5 volts
pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin
on the Arduino Board.

In order to generate the ultrasound you need to set the Trig on a High State for 10 µs.
That will send out an 8 cycle sonic burst which will travel at the speed sound and it will
be received in the Echo pin. The Echo pin will output the time in microseconds the
sound wave traveled.

For example, if the object is 10 cm away from the sensor, and the speed of the sound is
340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But
what you will get from the Echo pin will be double that number because the sound wave
needs to travel forward and bounce backward. So in order to get the distance in cm we
need to multiply the received travel time value from the echo pin by 0.034 and divide it
by 2.
Apparatus

● Ultrasonic Sensor HC-SR04


● Arduino Board
● Breadboard and Jumper Wires

Procedure

First you have to define the Trig and Echo pins. In this case they are the pins number 9
and 10 on the Arduino Board and they are named trigPin and echoPin. Then you need a
Long variable, named “duration” for the travel time that you will get from the sensor and
an integer variable for the distance.

In the setup you have to define the trigPin as an output and the echoPin as an Input and
also start the serial communication for showing the results on the serial monitor.

Program

1. // defines pins numbers


2. const int trigPin = 9;
3. const int echoPin = 10;
4.
5.
6. // defines variables
7. long duration;
8. int distance;
9.
10.
11. void setup() {
12. pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
13. pinMode(echoPin, INPUT); // Sets the echoPin as an Input
14. Serial.begin(9600); // Starts the serial communication
15. }
16.
17.
18. void loop() {
19. // Clears the trigPin
20. digitalWrite(trigPin, LOW);
21. delayMicroseconds(2);
22.
23.
24. // Sets the trigPin on HIGH state for 10 microseconds
25. digitalWrite(trigPin, HIGH);
26. delayMicroseconds(10);
27. digitalWrite(trigPin, LOW);
28.
29.
30. // Reads the echoPin, returns the sound wave travel time in microseconds
31. duration = pulseIn(echoPin, HIGH);
32.
33.
34. // Calculating the distance
35. distance= duration*0.034/2;
36.
37.
38. // Prints the distance on the Serial Monitor
39. Serial.print("Distance: ");
40. Serial.println(distance);
41. }

Você também pode gostar