Why is the digitalWrite output low in voltage?

Hi Team,

I have been trying various attempt without success, and really appreciate your help.

I am looking at example 18 and using port 8 as a control to kick start a Relay as attached.

The problem is that the current from port 8 will not be able to kick start the Relay. (I think the current is a bit low.) What should I do.

Thank you.

#include <dht11.h>
#include <LiquidCrystal.h>

int reading = 0; 
dht11 DHT11;

#define DHT11PIN 2
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);  //Define the connection LCD pin  
void setup()
{ 
     lcd.begin(16, 2);    // set up the LCD's number of columns and rows: 
     lcd.clear();         //Clears the LCD screen and positions the cursor in the upper-left corner 
     delay(1000); //延时1000ms
}
 
void loop()
{
    int chk = DHT11.read(DHT11PIN);
    
    int reading = DHT11.temperature;
    
      
    lcd.setCursor(0, 1); // set the cursor to column 0, line 0
    lcd.print("Temp:    ");// Print a message of "Temp: "to the LCD.
    lcd.print((float)DHT11.temperature, 2);// Print a centigrade temperature to the LCD. 
    lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.



    if (reading > 25) {
      digitalWrite(8, HIGH);
      
    } else {
      digitalWrite(8, LOW);
      
    }
    
  delay(1000);     
}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code.

You need to set the pin as an output via pinMode():
https://www.arduino.cc/en/Reference/PinMode
Since you didn’t do that you’re just activating/deacivating the internal pull up resistor.

Are you using a relay module or just the relay sugar cubes?

I am using the relay cube. my challenge is that the port 8 voltage is not sufficient to turn it on.

The pin does not have enough current to activate a relay. When you draw too much current, the voltage is pulled down. The answer is to use a transistor that can handle the current and control the transistor with the output.

I have tried also the following. no luck.

Is there any chance if you could help me with how to use transistor? I have been trying for a very long time. and my project is due very soon.

Thank you.

The battery ground (negative) goes to the MOSFET source, but must also go the the Arduino ground.
The MOSFET is not a logic level device so will not turn on fully (if at all) with 5V. To choose a proper MOSFET we need to know the required coil current and voltage.

I have also tried to ground the Mosfet to Ardrino board GND. ... any suggestion I will very very appreciated.

Post a data sheet for the relay or a clear photo of the markings on the relay.

racthree:
I am using the relay cube. my challenge is that the port 8 voltage is not sufficient to turn it on.

My challenge is having to ask you what voltage the relay is rated to work properly?

Please post all the relevant information first.

You will also need a flyback diode to protect your i/o pins.

I initially was using Relay: SRD-05VDC-SL-C (How to Set Up a 5V Relay on the Arduino - Circuit Basics)

then I tried also using Mosfet IRF 1405 (IRF1405 Datasheet)
Gate threshold is 2V-4V.

Thank you so much for your assistance.

I wonder if it is too much load on Arduino to have a temperature sensor, and then the LCD display. if I need to have the pin to have a High +5V?

Gate threshold is 2V-4V.

The gate threshold spec is the voltage that the MOSFET turns off. Not relevant when used as a switch. What you want to see is the voltage that Rds (drain-source on resistance) is specified. On your MOSFET the voltage is 10V so it needs 10V to be all the way on.

As you seem to have a track record here of ignoring what is said to you, have you now changed your code to make pin 8 into an output like you were told in reply #1?

racthree:
I initially was using Relay: SRD-05VDC-SL-C (How to Set Up a 5V Relay on the Arduino - Circuit Basics)

What on earth was wrong with using that relay module if you already had it with you?? why did you switch to the bare relay sugar cubes??

racthree:
I wonder if it is too much load on Arduino to have a temperature sensor, and then the LCD display. if I need to have the pin to have a High +5V?

Arduino i/o pins cannot supply enough current to drive a bare relay sugar cube anyway, whether you have additional components like a lcd display or not. Which is why you should use a transistor or a mosfet or get a ready made 5V relay module that takes logic input.

I have a few questions before one can help:

  • What it the operating voltage of your arduino?
  • Can you disconnect the relay from your output and determine if the output is on when you think it is?
    i.e. do you have a meter to test with?
  • I see the relay lists the operating voltage but I can't find enough data for the required current? We need that to help

JohnRob:

  • I see the relay lists the operating voltage but I can't find enough data for the required current? We need that to help

Which one? the one he initially used or the one which he uses now?

My million of apologies of didn't observed the following feeback earlier.

You need to set the pin as an output via pinMode():
https://www.arduino.cc/en/Reference/PinMode
Since you didn't do that you're just activating/deacivating the internal pull up resistor.

This now helps to get the trigger going on.