Test motor dc encoder 25GA370

Test using arduino mega 2560 and adafruit v1 motor shield this is my code

#include <AFMotor.h>

AF_DCMotor motor(1);
AF_DCMotor motor2(3);
volatile long int encoder_pos = 0;
volatile long int encoder_pos2 = 0;
//The sample code for driving one way motor encoder
const byte encoder0pinA = 18;//A pin -> the interrupt pin 0
const byte encoder0pinB = 31;//B pin -> the digital pin 3

const byte encoder1pinA = 19;//A pin -> the interrupt pin 0
const byte encoder1pinB = 33;//B pin -> the digital pin 3

byte encoder0PinALast;
byte encoder1PinALast;
int duration;//the number of the pulses
boolean Direction;//the rotation direction

void setup()
  Serial.begin(115200);//Initialize the serial port
//  EncoderInit();//Initialize the module

  attachInterrupt(digitalPinToInterrupt(encoder0pinA), encoder, RISING);

  attachInterrupt(digitalPinToInterrupt(encoder1pinA), encoder2, RISING);


void encoder(){

  if(digitalRead(encoder0pinB) == HIGH){

void encoder2(){

  if(digitalRead(encoder1pinB) == HIGH){

void loop()
//  motor.run(BACKWARD);
//  motor.setSpeed(40);
////  delay(200);
////  motor.run(BACKWARD);
////  motor.setSpeed(150);
////  delay(200);
//  motor2.run(FORWARD);
//  motor2.setSpeed(50);
//  delay(200);

//  motor2.run(FORWARD);
//  motor2.setSpeed(150);
//  delay(200);
  Serial.print("Encoder pos1:");
  Serial.print("Encoder pos2:");
  duration = 0;


void EncoderInit()
  Direction = true;//default -> Forward
  attachInterrupt(0, wheelSpeed, CHANGE);

void wheelSpeed()
  int Lstate = digitalRead(encoder0pinA);
  if((encoder0PinALast == LOW) && Lstate==HIGH)
    int val = digitalRead(encoder0pinB);
    if(val == LOW && Direction)
      Direction = false; //Reverse
    else if(val == HIGH && !Direction)
      Direction = true;  //Forward
  encoder0PinALast = Lstate;

  if(!Direction)  duration++;
  else  duration--;

Arduino Setting esp32-s2

When you failed upload to esp32 s2 maybe this setting can help you, the point is slow down your upload speed at 460800, and now upload not problem anymore.

STM32 (Bluepill) with i2c bme280

Sample code stm32duino upload via stlink

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() 
    bme.begin(0x76); //i2c address must declare,or try i2c scanner first
void loop() 
    Serial.print("Temperat: ");   
    Serial.print("Humidity: ");
    Serial.print("Pressure: ");     

5$ DIY radiation shield

I made some fun project for weather monitoring for measuring temperature, humidity, pressure using BME 680, lora modul and my first sensor like this

And after a couple days i realize the sensor measuring temperature is too high maybe because sensor measuring inside the box, after googling and looking other solution and my idea is making radiation shield and i end up with DIY radiation shield using some cheap plastic plates.

I bought 2$ for 8 plastic plates but i only use 6 because my sensor is small, and i also buy some spacer for mounting the plates its 2$ for 20 spacer i’m using 1 inches spacer, and 1$ for other material like cable ties and also spray paint

And this is it my cheap radiation shield 🙂 and i’m happy for the result

Happy Coding

Salam ngoprek

Arduino zero serial print not show

I bought The SAMD21 Mini is a Pro Mini-sized for the ATSAMD21G18 from bangood this is arduino zero clone platform and the form factor is really small and i think this is great replacement for arduino mini pro, this is the spec

  • ATSAMD21G18 32-bit/48MHz ARM Cortex-M0+
  • 256KB Flash Memory
  • 32KB SRAM32KB of EEPROM (emulated in Flash)
  • 22 GPIO Count 
  • 14 ADC Channels at 12-bit ResolutionAnalog-to-Digital and Digital-to-Analog Converters (ADC & DAC) 
  • RAW: 3.5V-6.0VVCC: 600mA  3.3V 
  • Pro Mini/Micro Layout
  • Integrated USB Controller

And today i connected this modul to Bosch sensor BME 680 modul using i2c connection, for the first time this board not print any Serial println, after browsing at internet i found the serial print must be activated by adding some command below

#define Serial SerialUSB

And this the complete code if you want to try it

Continue reading “Arduino zero serial print not show”

Mqtt publish wemos D1 Mini + dht22 in platform io

This is my weekend project using wemos D1 mini for publishing data to mqtt broker using platform io in visual studio code, here we go the code


Salam ngoprek

Happy Coding


STM32 Bluepill dan Arduino IDE di Ubuntu

Kali ini saya akan sharing mengenai cara menggunakan arduino IDE di STM32 Bluepill ok langsung saja begini caranya.

  1. Pastikan sudah memiliki stm32 bluepill
  2. Pastikan sudah menginstall arduino IDE
  3. Masuk ke board manager lalu install Arduino SAM Boards (32 bit ARM Cortex M3)
  4. Download library disini lalu unzip kemudian copykan foldernya ke dalam hardware di Arduino IDE
  5. Karena kita menggunakan ubuntu sebagai OS maka kita harus menginstall beberapa library yang sudah disediakan, caranya masuk ke hardware lalu ke Arduino_STM32 yang tadi kita masukkan lalu ke tools dan kemudian ke folder linux setelah itu klik kanan lalu klik open in terminal.
  6. Setelah terminal terbuka lalu ketikkan ./install.sh kemudian tinggal diikuti saja perintahnya dan selesai .
  7. Agar kita bisa upload via usb maka kita perlu memflash stm32 bluepill menggunakan firmware maple mini Continue reading “STM32 Bluepill dan Arduino IDE di Ubuntu”
%d bloggers like this: