The arduino car which can be bought from Aliexpress:
Motor Smart Robot Car Chassis Kit Speed Encoder Battery Box 2WD For Arduin
is equipped with a speed wheel. It should be equipped with a speed detector such as:
4 PIN Infrared Speed Sensor Module For Arduino/51/AVR/PIC 3.3V-5V
You should test it with the timerone library.
Install it in the Arduino library manager:
Sketch/ Include Library/Manage Libraries
This timer1 is used to get an accurate interval of one second instead of using the delay function.
Connect the D0 pin from the speed sensor to the D2 pin of the Arduino Nano. VCC to 5V and GND to GND of the Arduino.
Use the standard Arduino function attachinterrupt to use hardware interrupt whenever D2 pin goes high which indicates that a pulse or hole had been detected.
Refer to the code and description at:
https://brainy-bits.com/tutorials/speed-sensor-with-arduino/
However the code is so difficult to implement because it requires a motor controller and an analogue input. If we want to just test the speed of the wheel, use the modified code below:
#include <TimerOne.h>
unsigned int counter=0;
void docount() // counts from the speed sensor
{
counter++; // increase +1 the counter value
}
void timerIsr()
{
Timer1.detachInterrupt(); //stop the timer
Serial.print("Motor Speed: ");
int rotation = (counter); // number of pulses
Serial.print(rotation,DEC);
Serial.println(" Pulses per seconds");
counter=0; // reset counter to zero
Timer1.attachInterrupt( timerIsr ); //enable the timer
}
void setup()
{
Serial.begin(9600);
Timer1.initialize(1000000); // set timer for 1sec
attachInterrupt(0, docount, RISING); // increase counter when speed sensor pin goes High
Timer1.attachInterrupt( timerIsr ); // enable the timer
}
void loop()
{
}
Below is a picture of the placement of the Arduino Nano and LM298N motor controller with the speed sensor. The code above had been tested using this Arduino car.
No comments:
Post a Comment