Combining codes

I need help combining multiple codes

Codes:

  1. /*
    modified on Sep 28, 2020
    Modified by MohammedDamirchi from Arduino Examples
    Home
    */

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(20);
}

#include <LiquidCrystal.h>
int sensorValue;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup(){ lcd.begin(16, 2);
Serial.begin(9600); // sets the serial port to 9600
}
void loop(){sensorValue = analogRead(0); // read analog input pin 0
Serial.print("AirQua=");
Serial.print(sensorValue, DEC); // prints the value read
Serial.println(" PPM");
lcd.setCursor(0,0);
lcd.print("ArQ=");
lcd.print(sensorValue,DEC);
lcd.print(" PPM");
lcd.println(" ");
lcd.print(" ");
delay(100); // wait 100ms for next reading
}

#include <dht11.h>
#define DHT11PIN 4

dht11 DHT11;

void setup()
{
Serial.begin(9600);

}

void loop()
{
Serial.println();

int chk = DHT11.read(DHT11PIN);

Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);

Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);

delay(2000);

}

/*

modified on Sep 28, 2020
Modified by MohammedDamirchi from Arduino Examples
Home
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(20);
}

/*

modified on Sep 28, 2020
Modified by MohammedDamirchi from Arduino Examples
Home
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(20);
}

  1. #include <Wire.h>

#include <AHT10.h> //See the library download
link below!

AHT10Class AHT10;

void setup() {

Serial.begin(9600);

Wire.begin();

if
(AHT10.begin(eAHT10Address_Low))

Serial.println("Init AHT10 Success!");

else

Serial.println("Init AHT10 Failed!");

}

void loop() {

Serial.println("//Arduino & AHT10//");

Serial.println("Quick Test – Serial Monitor");

Serial.println(String("") + "Humidity(%RH):\t\t" +
AHT10.GetHumidity() + "%");

Serial.println(String("") + "Temperature(℃):\t"

  • AHT10.GetTemperature() + "℃");

Serial.println(String("") + "Dewpoint(℃):\t\t"

  • AHT10.GetDewPoint() + "℃");

    delay(1000);

}

#include <SoftwareSerial.h>
SoftwareSerial pmsSerial(2, 3);

void setup() {
// our debugging output
Serial.begin(115200);

// sensor baud rate is 9600
pmsSerial.begin(9600);
}

struct pms5003data {
uint16_t framelen;
uint16_t pm10_standard, pm25_standard, pm100_standard;
uint16_t pm10_env, pm25_env, pm100_env;
uint16_t particles_03um, particles_05um, particles_10um, particles_25um, particles_50um, particles_100um;
uint16_t unused;
uint16_t checksum;
};

struct pms5003data data;

void loop() {
if (readPMSdata(&pmsSerial)) {
// reading data was successful!
Serial.println();
Serial.println("---------------------------------------");
Serial.println("Concentration Units (standard)");
Serial.print("PM 1.0: "); Serial.print(data.pm10_standard);
Serial.print("\t\tPM 2.5: "); Serial.print(data.pm25_standard);
Serial.print("\t\tPM 10: "); Serial.println(data.pm100_standard);
Serial.println("---------------------------------------");
Serial.println("Concentration Units (environmental)");
Serial.print("PM 1.0: "); Serial.print(data.pm10_env);
Serial.print("\t\tPM 2.5: "); Serial.print(data.pm25_env);
Serial.print("\t\tPM 10: "); Serial.println(data.pm100_env);
Serial.println("---------------------------------------");
Serial.print("Particles > 0.3um / 0.1L air:"); Serial.println(data.particles_03um);
Serial.print("Particles > 0.5um / 0.1L air:"); Serial.println(data.particles_05um);
Serial.print("Particles > 1.0um / 0.1L air:"); Serial.println(data.particles_10um);
Serial.print("Particles > 2.5um / 0.1L air:"); Serial.println(data.particles_25um);
Serial.print("Particles > 5.0um / 0.1L air:"); Serial.println(data.particles_50um);
Serial.print("Particles > 10.0 um / 0.1L air:"); Serial.println(data.particles_100um);
Serial.println("---------------------------------------");
}
}

boolean readPMSdata(Stream *s) {
if (! s->available()) {
return false;
}

// Read a byte at a time until we get to the special '0x42' start-byte
if (s->peek() != 0x42) {
s->read();
return false;
}

// Now read all 32 bytes
if (s->available() < 32) {
return false;
}

uint8_t buffer[32];
uint16_t sum = 0;
s->readBytes(buffer, 32);

// get checksum ready
for (uint8_t i=0; i<30; i++) {
sum += buffer[i];
}

/* debugging
for (uint8_t i=2; i<32; i++) {
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", ");
}
Serial.println();
*/

// The data comes in endian'd, this solves it so it works on all platforms
uint16_t buffer_u16[15];
for (uint8_t i=0; i<15; i++) {
buffer_u16[i] = buffer[2 + i2 + 1];
buffer_u16[i] += (buffer[2 + i
2] << 8);
}

// put it into a nice struct :slight_smile:
memcpy((void *)&data, (void *)buffer_u16, 30);

if (sum != data.checksum) {
Serial.println("Checksum failure");
return false;
}
// success!
return true;
}

const int pinPM25 = 7;
const int pinPM1 = 8;
const unsigned long sampleTime = 5000; // mSec -> 5..30 sec

float calc_low_ratio(float lowPulse) {
return lowPulse / sampleTime * 100.0; // low ratio in %
}

float calc_c_mgm3(float lowPulse) {
float r = calc_low_ratio(lowPulse);
float c_mgm3 = 0.00258425 * pow(r, 2) + 0.0858521 * r - 0.01345549;
return max(0, c_mgm3);
}

float calc_c_pcs283ml(float lowPulse) {
float r = calc_low_ratio(lowPulse);
float c_pcs283ml = 625 * r;
return min(c_pcs283ml, 12500);
}

void setup() {
Serial.begin(9600);
pinMode(pinPM25, INPUT);
pinMode(pinPM1, INPUT);
Serial.println("Warming up...");
// delay(60000); // 1 minute warm-up
}

void loop() {
static unsigned long t_start = millis();
static float lowPM = 0;

lowPM += pulseIn(pinPM25, LOW) / 1000.0; // >2.5µm (PM2.5)
//lowPM += pulseIn(pinPM1, LOW) / 1000.0; // >1µm (PM1)

if ((millis() - t_start) >= sampleTime) {
Serial.print("low_% PM : ");
Serial.println(calc_low_ratio(lowPM));
Serial.print("c_mgm3 PM : ");
Serial.println(calc_c_mgm3(lowPM));
Serial.print("c_pcs283ml PM: ");
Serial.println(calc_c_pcs283ml(lowPM));
Serial.println();
lowPM = 0;
t_start = millis();
}
}

Please help

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Please post your best attempt at combining the two sketches, describe what it should do and what problems you have

Normally, I’d never suggest usin Al to work your code, but you may learn something.

Corrected:
Can you walk through the code and explain exactly what each line does, and why ?

Only then can you expect to understand what you’re asking us.

Did auto-correct help you write this :grinning:

LOL!, just leave it to Al and its friends

Corrected :

I suggest looking at https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay/ and understanding how to perform an action after a specific time has elapsed.

You might try to extend the example by flashing a second LED at a different rate. Once you have the concept, then you can combine multiple codes easily.

We need for you to edit your post as requested by @UKHeliBob because your code could be hard to read and, most commonly, unable to be compiled for us while trying to check it out.

Then, you need to better describe what you mean with "combining", and show us at least the code of one of your tries. We won't do the work for you.

could you please combine the codes for me. I dont know how to code

I need all codes into one code

This forum is not a code writing service, unless you are prepared to pay for it. Are you prepared to pay ?

how much do I need to pay

The price will depend on who, if anyone, is willing to do what you want. Much more information will be required before a price can be quoted

Do you want me to move this topic to the forum category for paid help ?

Sorry I had a tutorial on this but my internet service provider pulled the plug on the free web space they offered and took my whole site off line and didn't even offer a web redirection service. Tech support says every time they suggest this the CEO of the company says it will cost hundreds of thousand pounds to implement.
This file

Merging_Code.zip (663.3 KB)

When un-compressed you can double click the .HTML file and it should load just that page into your default browser. Let me know if you have any problems with this. Of course none of the links off this page will work.

yes

The topic has been moved to the Jobs and Paid Consultancy category of the forum

3 of the codes appear to be identical, so that makes it easier.

An specification of the goals for the combined codes would help. Is the goal to display on the LCD, or the serial monitor, or both?

Combining the sketches you show may depend on

  1. IF the libraries they use will fit in you board, not fill the program space.
  2. IF none of the libraries uses blocking code, like have delay() or internal loops.
  3. IF the libraries do not conflict with each other, like use the same interrupt(s).

Beyond that, the delay() calls in your void loop() codes all have to be replaced with what members call millis-code which is down to technique, cut&dry work.

I don't know about all the libraries you use.

One thing for sure, Serial should begin at 115200, not 9600.

pls make the code for me

for free