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.
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.
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.
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?
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.
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.