digitalWrite LOW at start - possible ?

Hi guys.
i have a short question.
Is it possible to set digitalWrite(EngineON, LOW); at the Start of arduino?
im asking because every time im turning arduino on pins are immediately HIGH and i want em to be LOW immediately when I turn on the power.

i've tried to write "digitalWrite(EngineON, LOW);" in void setup() but it doesnt work. :frowning:
PLZ help :slight_smile:

You could try adding a pull down resistor to keep the pin low until its driven HIGH by the Arduino.

I agree with what pYro_65 said, but digitalWrite(EngineON, LOW) in setup() should have worked. Perhaps there is something wrong in the code that you didn't show us, or perhaps your unspecified Arduino is broken, or perhaps your wiring (again, not revealed) has something wrong.

You asked to "...immediately..." set a pin low, but then you attempted to set it low in setup(). This is not "immediately" as I would define it. What do you really want to do?

It's more likely the way you have wired your project. Do you have a schematic.

BTW DON'T use pin13

I agree with what pYro_65 said, but digitalWrite(EngineON, LOW) in setup() should have worked.

Three things to think about,

  1. What (if any thing) does the chip do on reset!

  2. What does the bootloader do?.

  3. what does init() do?

All the above run before setup()!!!!

Mark

PS a pull down resistor is not the way to go look at using an RC net.

M

holmes4:
Three things to think about,

  1. What (if any thing) does the chip do on reset!

  2. What does the bootloader do?.

  3. what does init() do?

All the above run before setup()!!!!

All of the things you mention happen long after power up. I too have observed random pin states at power on. I had to use this method to stop a multiplex from flickering on power up/restart. It might not be the best method, but it seemed to work well.

There are a possible 10 steps (5 mostly unused) that run during the startup of an AVR, clearing the ports and registers is the fifth! There can be a substantial amount of time passed before the .bss and registers are zeroed.

What is an RC net?

I would be inclined to express the problem a little differently. "How do I ensure the input to device X stays LOW before and during Arduino start up"

I can't see any problem using a pull-down resistor for that as long as it has a suitable value that does not prevent subsequent working.

...R

vaj4088:
I agree with what pYro_65 said, but digitalWrite(EngineON, LOW) in setup() should have worked. Perhaps there is something wrong in the code that you didn't show us, or perhaps your unspecified Arduino is broken, or perhaps your wiring (again, not revealed) has something wrong.

You asked to "...immediately..." set a pin low, but then you attempted to set it low in setup(). This is not "immediately" as I would define it. What do you really want to do?

i dont know what is wrong in my code. everythig works fine except digitalWrite(EngineON, LOW) in setup().

i want my arduino to dont set HIGH when i turn it on or reset it. because relay modules will be starting my fiat 126p. so now when arduino is setting HIGH immiedietly after turning on my engine is working. i want it to be LOW because i wanna control engine/car via bluetooth. you know what i mean?
so if setting it in setup() is not immediately (and doesnt work) - how to do in immediately ?? :slight_smile:

harry37:
i dont know what is wrong in my code. everythig works fine except digitalWrite(EngineON, LOW) in setup().

This is not a very good description.

I presume you are NOT saying that digitalWrite(EngineON, LOW) actually makes the output HIGH?
I presume you do have pinMode() before digitalWrite()

So are you saying that the pin can be HIGH before the digitalWrite() takes effect?

...R

Robin2:
This is not a very good description.

I presume you are NOT saying that digitalWrite(EngineON, LOW) actually makes the output HIGH?
I presume you do have pinMode() before digitalWrite()

So are you saying that the pin can be HIGH before the digitalWrite() takes effect?

...R

its true that digitalWrite(EngineON, LOW) makes output high - it seems to be swithed: digitalWrite low makes HIGH and digitalWrite high makes LOW. i dont know why. but main question is how to set pin low after turning arduino on.

here is a code: :slight_smile:

#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 /-(Connect to Pin 2 )-/
OneWire ourWire(ONE_WIRE_BUS);
DallasTemperature sensors(&ourWire);
int temp;
int EngineON = 11;
int Elektr = 12;
int state;
int bt;
int srv=13;
boolean stA=0;
boolean stD=0;
Servo myservo;
int pos = 90;

void setup() {
myservo.attach(13); // initialize the digital pin as an output.
pinMode(srv, OUTPUT);
pinMode(EngineON, OUTPUT);
pinMode(Elektr, OUTPUT);
Serial1.begin(9600); // initialize serial communication at 9600 bits per second:
sensors.begin(); //( Start up the DallasTemperature library )
}

void loop() {

if (Serial1.available() > 0){
state = Serial1.read(); }
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
Serial1.write(temp);

if (state == '3') {
digitalWrite(EngineON, HIGH);} // rozrusznik on 11

else if (state == '2') {
digitalWrite(EngineON, LOW);} // rozrusznik off 11

else if (state == '5') {
digitalWrite(Elektr, HIGH);} // wyłaczenie 12

else if (state == '1') { // zapłon ssanie 12
digitalWrite(Elektr, LOW);

if (state == '4') {
if (state == 'a') {
pos=pos+2;
myservo.write(pos);
delay(15);
}

else if (state == 'b') {
pos=pos-2;
myservo.write(pos);
delay(15);
}
}
else {
sensors.requestTemperatures();// start temperatury // Send the command to get temperatures
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" Degrees C");
temp = sensors.getTempCByIndex(0);}

if (temp < 28) {
pos=0;
myservo.write(pos);}

else if (temp > 28 && temp < 50) {
pos=36;
myservo.write(pos);}

else if (temp > 50 && temp < 75) {
pos=72;
myservo.write(pos);}

else if (temp > 75 && temp < 100) {
pos=108;
myservo.write(pos);}

else if (temp > 100 && temp < 150) {
pos=144;
myservo.write(pos);}

else if (temp > 150) {
pos=180;
myservo.write(pos);}
// koniec temperatury

}

delay(100);
}

// wait for 100ms

i dont know what is wrong in my code. everythig works fine except digitalWrite(EngineON, LOW) in setup().

I can't help noticing that you do not have it in your code, maybe that is the problem.

Remember during the time when the boot loader is looking to see if new code needs to be uploaded then the pins are defined as inputs.
If you do digital writes on input pins that are inputs You are turning on and off the pull up resistors which might look like an upside down output.

I don't know about others, but I expected to see

digitalWrite(EngineON, LOW)

in setup()

 if (Serial1.available() > 0){ 
      state = Serial1.read(); }

What will state be set to if there is no serial input to read ?

Grumpy_Mike:
I can't help noticing that you do not have it in your code, maybe that is the problem.

Remember during the time when the boot loader is looking to see if new code needs to be uploaded then the pins are defined as inputs.
If you do digital writes on input pins that are inputs You are turning on and off the pull up resistors which might look like an upside down output.

Guys... i dont have it in my code cause it doesnt work. dont cause any effect.
i want u to tell me why it doesnt work and is it possible to set this pins low at start? Pins can not even blink while power is turning on. is it possible ?

Change this:

void setup() {                
  myservo.attach(13); // initialize the digital pin as an output.
  pinMode(srv, OUTPUT); 
  pinMode(EngineON, OUTPUT); 
  pinMode(Elektr, OUTPUT); 
  Serial1.begin(9600); // initialize serial communication at 9600 bits per second:
  sensors.begin(); //( Start up the DallasTemperature library )
 }

To this:

void setup() {                
  pinMode(EngineON, OUTPUT); 
  digitalWrite(EngineON, LOW);
  myservo.attach(13); // initialize the digital pin as an output.
  pinMode(srv, OUTPUT); 
  pinMode(Elektr, OUTPUT); 
  Serial1.begin(9600); // initialize serial communication at 9600 bits per second:
  sensors.begin(); //( Start up the DallasTemperature library )
 }

and recompile and upload and tell us what happens

By the way, you have other problems within your loop in your If statements that will mean that it doesn't do what you want, if you indent properly you'll see it more clearly.

And you're using 13 for your servo, you do know that the system uses 13 as the LED on the board, right?

Guys... i dont have it in my code cause it doesnt work. dont cause any effect.
i want u to tell me why it doesnt work and is it possible to set this pins low at start? Pins can not even blink while power is turning on. is it possible ?

It depends on WHERE you put it, just saying it doesn't work is no good to anyone.

If you want to know why it does not work then you have to include all your code including the bits that do not work because in that way we can replicate that and see why you are mistakenly thinking it does not work.

Of course 'digitalWrite(EngineON, LOW)' works, do you think you are the first to spot something used as many times as this. You are misunderstanding something and we are trying to help you find out what it is. If you don't want to cooperate then you are free to stop bothering us.

@Grumpy_Mike beat me to it by a few seconds

Of course 'digitalWrite(EngineON, LOW)' works

...R

@Grumpy_mike i told twice that it doesnt work in setup().

@darkroomsource understood this very well.

i've done it as darkroomsource said and it's working ! :smiley: THX :slight_smile:

void setup() {
pinMode(EngineON, OUTPUT);
digitalWrite(EngineON, HIGH);
myservo.attach(13); // initialize the digital pin as an output.
pinMode(srv, OUTPUT);
pinMode(Elektr, OUTPUT);
digitalWrite(Elektr, HIGH);
Serial1.begin(9600); // initialize serial communication at 9600 bits per second:
sensors.begin(); //( Start up the DallasTemperature library )
}

i dont know why it didnt working as i tried to do it in the same way. maybe order of the lines is important?

But now here is a next question... as u can see in a code above digitalWrite is set to HIGH and in fact pins are LOW because relay leds are off.
And in fact in whole my code digitalWrite HIGH means that pins are low.
can someone explain it to me? :slight_smile:

But now here is a next question... as u can see in a code above digitalWrite is set to HIGH and in fact pins are LOW because relay leds are off.
And in fact in whole my code digitalWrite HIGH means that pins are low.
can someone explain it to me? :slight_smile:

Looks normal.

On most relay modules, the visible LED is connected so it comes on when the module's input is driven LOW. Also, the relay's coil will be energized.

HIGH will turn off both the relay and LED.

This makes no sense at all. How can you reconcile the three lines I have marked ? ? ?

harry37:
@Grumpy_mike i told twice that it doesnt work in setup(). <---------------------

@darkroomsource understood this very well. <---------------------------

i've done it as darkroomsource said and it's working ! :smiley: THX :slight_smile:

void setup() {
pinMode(EngineON, OUTPUT);
digitalWrite(EngineON, HIGH); <-----------------------------------------------
myservo.attach(13); // initialize the digital pin as an output.
pinMode(srv, OUTPUT);
pinMode(Elektr, OUTPUT);
digitalWrite(Elektr, HIGH);
Serial1.begin(9600); // initialize serial communication at 9600 bits per second:
sensors.begin(); //( Start up the DallasTemperature library )
}

i dont know why it didntworking as i tried to do it in the same way. maybe order of the lines is important?

I hope the words in bold were meant as a joke.

above digitalWrite is set to HIGH and in fact pins are LOW

This does not make sense either. I have 4 Arduinos and on ALL of them digitalWrite(pin, HIGH); causes that pin to output 5 volts (provided I have pinMode() set to OUTPUT). If you are seeing 0 volts somewhere it will NOT be at the Arduino pin. But you are not telling us exactly where you are detecting the LOW voltage.

...R

... in fact pins are LOW because relay leds are off

Shouldn't ASSUME.

Now, if you take into account the reverse logic of the LED connections, then all of a sudden, everything looks normal.