Exactly what range have you got selected on the multimeter and are you sure that you have the leads plugged into the correct sockets on the meter ? The positive socket for current ranges is often not the same as that used to measure voltage
What is the resistance? The image shows as brown-brown-brown, which would be 110 ohms IIRC, which, if the Arduino output is high, should result in 5-(~2.1)/110 = 26 ma. Looking at it the other way, if the output is high and that's a green LED and the current is correct, the resistance is 44 k Ohms. Depends, of course, on what the green LED's real voltage drop is at such low currents.
You're right, its a 110 omh resistor. Voltage measures at 3.65. So that would be 33mA right?
So why is it showing as 66Microamps? A reading that low cannot be a correct reading right?
If you have a multimeter, measure the resistor. If the meter has a diode-test feature, use it to test the LED. Something is fishy, nobody's repealed Ohms Law, last I checked.
That current would be correct if the pin was not set to OUTPUT with pinMode().
Then you would only measure pull up current with digitalWrite HIGH.
Leo..
@Wawa Nice spot.
My bad, folks, I didn't do the usual "Please post your code and your schematic", which would likely have resulted in a "PINMODE???? comment. I should have twigged to it when I back-calculated the resistance at something near 50k.
Lesson for the OP, post your code even when you don't think it's relevant. It invariably has some relevance.
I thought this may be the issue yesterday but after changing the code, I found similar readings.
I'm sure its just another mistake on my behalf.
Preformatted text
#include <Servo.h> //Include servo library
// constants won't change
const int TRIG_PIN = 6; // Arduino pin connected to Ultrasonic Sensor's TRIG pin
const int ECHO_PIN = 7; // Arduino pin connected to Ultrasonic Sensor's ECHO pin
const int SERVO_PIN = 9; // Arduino pin connected to Servo Motor's pin
const int SERVO_PIN2 = 3; // Arduino pin connected to Servo Motor's pin
const int DISTANCE_THRESHOLD = 50; // threshold for sensor HIGH set to 50cm
const int WHITE_led = 11;
const int GREEN_led = 12;
Servo servo; // create servo object to control a servo
Servo servo2; // create servo object to control a servo
// variables will change:
float duration_us, distance_cm; // Claryfying We want the ultrasonic sensor to disply units as cm
void setup() {
Serial.begin (9600); // initialize serial port
pinMode(TRIG_PIN, OUTPUT); // set arduino pin to output mode
pinMode(ECHO_PIN, INPUT); // set arduino pin to input mode
servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object
servo2.attach(SERVO_PIN2); // attaches the servo on pin 3 to the servo object
servo.write(0); // gives a Value to the servo, giving it an initial position
servo2.write(-0); // gives a Value to the servo, giving it an initial position (- lets it know to move in the opposite direction)
pinMode(WHITE_led, OUTPUT);
pinMode(GREEN_led, INPUT);
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10); //wait 10 microseconds
digitalWrite(TRIG_PIN, LOW); //turn off ping
// measure duration of pulse from ECHO pin
duration_us = pulseIn(ECHO_PIN, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
if(distance_cm < DISTANCE_THRESHOLD) //If Sensor isnt triggered
{
Serial.println ("Nobody Is Infront Of the Sensor");
digitalWrite (WHITE_led, HIGH); //turn on white LED
delay (500); // DELAY 1/2 second before turning green LED off
digitalWrite (GREEN_led, LOW);//turn off green LED
}
else
{
Serial.println ("Someone Is Infront Of the Sensor");
delay(2000);// 2 second delay before turning green LED on and white off
digitalWrite (WHITE_led, LOW); //turn off white LED
digitalWrite (GREEN_led,HIGH); //turn ON Green LED
}
if(distance_cm < DISTANCE_THRESHOLD){ //IF Sensor is triggered
servo.write(90); // rotate servo motor to 90 degree
servo2.write(90); // rotate servo motor to 90 degree
delay(5000);// Stay opend for 5 seconds when sensor stops detecting something
}
else{
servo.write(0); // rotate back to original position
servo2.write(180); // rotate back to original position
}
// print the value to Serial Monitor
Serial.print("distance: "); //prints data as tecxt onto the serial port (prints 'distance:' before the distance mesured)
Serial.print(distance_cm); //prints data as text onto the serial port (prints the distance mesured in cm)
Serial.println(" cm"); //prints data as text onto the serial port (claryfies to print 'cm' at the end of distance)
delay(500); // delay before starting loop again
I give up. Please post your most recent version of code, along with correct and up to date "anomalous behaviour" that corresponds to that same version of code. No foolin', one more oopsie and I'll leave this to others.
yes I noticed that straight after posting, that's why I replied that that was a mistake made by me straight after posting.
it stays the same after I change it
Give me a break, this is my first post on this forum, no need to get touchy about an Arduino project is there...
#include <Servo.h> //Include servo library
// constants won't change
const int TRIG_PIN = 6; // Arduino pin connected to Ultrasonic Sensor's TRIG pin
const int ECHO_PIN = 7; // Arduino pin connected to Ultrasonic Sensor's ECHO pin
const int SERVO_PIN = 9; // Arduino pin connected to Servo Motor's pin
const int SERVO_PIN2 = 3; // Arduino pin connected to Servo Motor's pin
const int DISTANCE_THRESHOLD = 50; // threshold for sensor HIGH set to 50cm
const int WHITE_led = 11;
const int GREEN_led = 12;
Servo servo; // create servo object to control a servo
Servo servo2; // create servo object to control a servo
// variables will change:
float duration_us, distance_cm; // Claryfying We want the ultrasonic sensor to disply units as cm
void setup() {
Serial.begin (9600); // initialize serial port
pinMode(TRIG_PIN, OUTPUT); // set arduino pin to output mode
pinMode(ECHO_PIN, INPUT); // set arduino pin to input mode
servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object
servo2.attach(SERVO_PIN2); // attaches the servo on pin 3 to the servo object
servo.write(0); // gives a Value to the servo, giving it an initial position
servo2.write(-0); // gives a Value to the servo, giving it an initial position (- lets it know to move in the opposite direction)
pinMode(11, OUTPUT);
pinMode(GREEN_led, OUTPUT);
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10); //wait 10 microseconds
digitalWrite(TRIG_PIN, LOW); //turn off ping
// measure duration of pulse from ECHO pin
duration_us = pulseIn(ECHO_PIN, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
if(distance_cm < DISTANCE_THRESHOLD) //If Sensor isnt triggered
{
Serial.println ("Nobody Is Infront Of the Sensor");
digitalWrite (WHITE_led, HIGH); //turn on white LED
delay (500); // DELAY 1/2 second before turning green LED off
digitalWrite (GREEN_led, LOW);//turn off green LED
}
else
{
Serial.println ("Someone Is Infront Of the Sensor");
delay(2000);// 2 second delay before turning green LED on and white off
digitalWrite (WHITE_led, LOW); //turn off white LED
digitalWrite (GREEN_led,HIGH); //turn ON Green LED
}
if(distance_cm < DISTANCE_THRESHOLD){ //IF Sensor is triggered
servo.write(90); // rotate servo motor to 90 degree
servo2.write(90); // rotate servo motor to 90 degree
delay(5000);// Stay opend for 5 seconds when sensor stops detecting something
}
else{
servo.write(0); // rotate back to original position
servo2.write(180); // rotate back to original position
}
// print the value to Serial Monitor
Serial.print("distance: "); //prints data as tecxt onto the serial port (prints 'distance:' before the distance mesured)
Serial.print(distance_cm); //prints data as text onto the serial port (prints the distance mesured in cm)
Serial.println(" cm"); //prints data as text onto the serial port (claryfies to print 'cm' at the end of distance)
delay(500); // delay before starting loop again
}
To be clear, I don't give a rats patootie about what a simulator tells you when you've got available hardware. It's just another source of confusion, and another source of cut-and-paste errors, plus communications snafus when one person talks about simulator results while another is expecting hardware results.
Does the LED work? Seems so, you've got some form of light emission, but I'd say wire it from 5v to resistor to LED to ground, and verify the resistor you're using gives the light you expect.
verify you can turn on and off the digital output you wish to drive the LED with. Write a code that sets the output to 0, 1, 0 repetitively, with a couple of seconds delay between changes, and with a voltmeter, verify the output changes state.
wire the LED to the output, and verify that it goes on and off.
This may seem insulting and boring, but we're at hour 20 now on a basic electronics step that should be resolved in 5-10 minutes. Something isn't jiving here.